//
//  NetBaiduManager.m
//  car
//
//  Created by chenxu on 15/3/23.
//  Copyright (c) 2015年 chenxu. All rights reserved.
//

#import "NetBaiduManager.h"
#import "NetBaiduClient.h"
#import "BConnector.h"

@implementation NetBaiduManager


+ (instancetype)sharedManager {
    static NetBaiduManager *shared_manager = nil;
    static dispatch_once_t pred;
    dispatch_once(&pred, ^{
        shared_manager = [[self alloc] init];
    });
    return shared_manager;
}

- (void)request_PrivateMessages:(PrivateMessages *)priMsgs andBlock:(void (^)(id data, NSError *error))block{
    priMsgs.isLoading = YES;
    [[NetBaiduClient sharedJsonClient]requestJsonDataWithPath:[BConnector toPathWithChannelid] withParams:[BConnector toParams:fetch_msgs_single] withMethodType:Post andBlock:^(id data, NSError *error) {
        priMsgs.isLoading = NO;
        
        //从data转换出primsg实体
        if (data) {
            block(data,nil);
        }
        else{
            block(nil,error);
        }
        
        
    }];
}


/*!
 *  @brief  发一条消息
 *  @param nextMsg 要发送的下一条消息
 *  @param block   回调
 */
- (void)push_PrivateMessage:(PrivateMessage *)nextMsg andOrder:(Order*)order andBlock:(void (^)(id data, NSError *error))block{
    if([order.device  isEqual: @"1"]) {
        [BConnector setPlatform:android];
    }
    else if ([order.device  isEqual: @"2"]){
        [BConnector setPlatform:ios];
    }
    else{
        [BConnector setPlatform:android];
    }
    nextMsg.sendStatus = PrivateMessageStatusSending;
    [[NetBaiduClient sharedJsonClient]requestJsonDataWithPath:[BConnector toPath] withParams:[BConnector toMsgParams:push_msg_to_single msg:nextMsg order:(Order*)order] withMethodType:Post andBlock:^(id data, NSError *error) {
        
        bool success = [[data valueForKeyPath:@"response_params.success_amount"] integerValue] !=0 ?true:false;
        
        if (success) {
            nextMsg.sendStatus = PrivateMessageStatusSendSucess;
            block(data,nil);
        }
        else{
            nextMsg.sendStatus = PrivateMessageStatusSendFail;
            block(nil,error);

        }
        
    }];
}

- (void)pushToall_PrivateMessage:(PrivateMessage *)nextMsg andOrder:(Order*)order andBlock:(void (^)(id data, NSError *error))block{
    [[NetBaiduClient sharedJsonClient]requestJsonDataWithPath:[BConnector toPath] withParams:[BConnector toMsgParams:push_msg_to_all msg:nextMsg order:(Order*)order] withMethodType:Post andBlock:^(id data, NSError *error) {
        
        
        
    }];
}


- (void)query_bindlist:(void (^)(id data, NSError *error))block{
    [[NetBaiduClient sharedJsonClient]requestJsonDataWithPath:[BConnector toPath] withParams:[BConnector toParams:query_bindlist] withMethodType:Post andBlock:^(id data, NSError *error) {
        
        
        
    }];
}

- (void)query_app_ioscert:(PrivateMessage *)nextMsg andBlock:(void (^)(id data, NSError *error))block{
    [[NetBaiduClient sharedJsonClient]requestJsonDataWithPath:[BConnector toPathWithChannelid] withParams:[BConnector toParams:query_app_ioscert] withMethodType:Post andBlock:^(id data, NSError *error) {
        
        
        
    }];
}


@end
